package com.d0319;
public class BankTest extends Thread{
    static int money =1000;
    static Object object=new Object();
    @Override
    public void run() {
        while (money >0){
            synchronized (object){
                money=money-100;
                System.out.println(Thread.currentThread().getName()+"取走了100元，还剩"+money+"元");

            }
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        Thread thread1=new Thread(new BankTest(),"A");
        Thread thread2=new Thread(new BankTest(),"B");
        thread1.start();
        thread2.start();
    }
}


